import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.WriteAbortedException;
import java.io.Writer;
import java.nio.CharBuffer;
import java.util.Scanner;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.*;
public class search
{
	static Model model = ModelFactory.createDefaultModel();
	
	public static void main(String[] args) throws IOException
	{		
		search sample= new search();
		model.read("D:\\eclipse\\workspace\\keyword-search\\foaf.rdf");
		sample.querywithFilter();	
	}

	
	public void querywithFilter() throws IOException 
	{
		Scanner input = new Scanner(System.in);
        String keyword = input.nextLine();
		String queryString1 = 
			"PREFIX foaf: <http://xmlns.com/foaf/0.1#> " +
			"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
			"SELECT ?s ?p ?o " +
			"WHERE {?s ?p ?o} " +
			//"SELECT ?PlayerfromEngland " +
			//"WHERE {?PlayerfromEngland rdf:type soccer:Player." +
			//"?PlayerfromEngland soccer:nationality ?n " +
			"  FILTER(?s = " + keyword + " )} ";
	
		Query query1 = QueryFactory.create(queryString1);
		QueryExecution qe1 = QueryExecutionFactory.create(query1, model);
		ResultSet results1 = qe1.execSelect();
		ResultSetFormatter.out(System.out, results1, query1);
	
		// Remember to free the used resources during running the query
		qe1.close();
	}
	
}

